package lvm

import "context"

func VGRename(ctx context.Context, oldName string, newName string) (vg *VolumeGroup, err error) {
	// 检查旧的是否存在
	if getVG(ctx, oldName) == nil {
		err = ErrNotFound
		return
	}
	// 检查新的是否已存在
	if getVG(ctx, newName) != nil {
		err = ErrExists
		return
	}

	_, err = execCommand(ctx, "vgrename", oldName, newName)
	if err != nil {
		return
	}

	vg = getVG(ctx, newName)
	if vg == nil {
		err = ErrCommand
	}
	return
}
